<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>这是子传父</title>
</head>

<body>
    <div id="root">
        <hello @add-item="addItmes"></hello>
        <ul>
            <li v-for='arr in array' :key='arr.id'>{{arr.title}}</li>
        </ul>
    </div>
    <script src="../libs/vue/vue.js"></script>
    <script>
        new Vue({
            el: '#root',
            data: {
                array: [{
                    id: 1,
                    title: '这是子传父',
                    completed: true
                }]

            },
            methods: {
                addItmes(arr) {
                    this.array.push({
                        id: Math.random(),
                        title: arr,
                        completed: false
                    })
                }
            },
            components: {
                'hello': {
                    template: `
                    <div>
                        <input type="text" v-model="inputValue">
                        <button @click="handle">添加</button> 
                    </div>
                    `,
                    data() {
                        return {
                            inputValue: ''
                        }
                    },
                    methods: {
                        handle() {
                            console.log('wozaizhge ')
                            this.$emit('add-item', this.inputValue)
                            console.log(this.inputValue)
                            this.inputValue = ""
                        }
                    }
                }
            }
        })
    </script>
</body>

</html>